<script type="text/javascript" src="/bootstrap_datetimepicker/bootstrap-datetimepicker.js"></script>
<link rel="stylesheet" type="text/css" href="/bootstrap_datetimepicker/bootstrap-datetimepicker.css">
<script type="text/javascript" src="/bootstrap_datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<style>
    .table>thead>tr>th{background: #ddd;}
    .table>tbody>tr>td ,.table>thead>tr>th{padding:8px;line-height:2;vertical-align:bottom;border-bottom:1px solid #ddd;}
    .col-md-12{background:#ffffff;}
    .form-inline>button{height: 40px;width: 100px;font-size: 16px;}
    .form-inline .form-group>input{border-radius:3px;}
    .modal-body .form-group>label{margin-left: 35px;float:left;margin-right: 10px;padding-top: 8px;width: 100px;}
    .modal-body .form-group>input{width: 65%;}

    .btn-group{margin-top: 20px;margin-bottom: 20px;}
    .btn{width: 150px;height: 45px;}

</style>
<body>
<div class="btn-group">
    <a href="details?id=<?php if(!empty($_GET['id'])){echo $_GET['id'];}?>"><button type="button" class="btn btn-default btn-top">基 础 档 案</button></a>
    <a href="measure?id=<?php if(!empty($_GET['id'])){echo $_GET['id'];}?>"><button type="button" class="btn btn-default btn-top">测 糖 记 录</button></a>
    <a href="insulin?id=<?php if(!empty($_GET['id'])){echo $_GET['id'];}?>"><button type="button" class="btn btn-primary btn-top">用 药 记 录</button></a>
</div>
<form class="form-inline" role="form" style="margin-top: 20px;margin-bottom: 20px;">
    <div class="form-group" style="width: 45%;">
        <select class="form-control" style="height: 40px;width: 200px;color:#999999;border-radius:3px;" id="meals">
            <option value="0">请选择餐别类型</option>
            <option value="1" <?php if(isset($_GET['meals'])&&$_GET['meals']==1){echo 'selected';} ?>>早餐前</option>
            <option value="3" <?php if(isset($_GET['meals'])&&$_GET['meals']==2){echo 'selected';} ?>>中餐前</option>
            <option value="5" <?php if(isset($_GET['meals'])&&$_GET['meals']==3){echo 'selected';} ?>>晚餐前</option>
            <option value="7" <?php if(isset($_GET['meals'])&&$_GET['meals']==4){echo 'selected';} ?>>睡前</option>
        </select>
        <select class="form-control" style="height: 40px;width: 200px;color:#999999;border-radius:3px;" id="state">
            <option value="0">请选择注射方式</option>
            <option value="1" <?php if(isset($_GET['state'])&&$_GET['state']==1){echo 'selected';} ?>>按处方建议</option>
            <option value="2" <?php if(isset($_GET['state'])&&$_GET['state']==2){echo 'selected';} ?>>手动添加</option>
        </select>
        <input type="text" class="form-control" id="time_start" autocomplete="off" value="<?php if(!empty($_GET['maked_at'])){echo explode('|',$_GET['maked_at'])[0];}?>" placeholder="开始时间" style="margin-left:20px;width: 150px;height: 40px;"> -
        <input type="text" class="form-control" id="time_end" autocomplete="off" value="<?php if(!empty($_GET['maked_at'])){echo explode('|',$_GET['maked_at'])[1];}?>" placeholder="结束时间" style="width: 150px;height: 40px;">
    </div>
    <button type="button" class="btn btn-primary" id="select" style="margin-left: 10%;">查询</button>
    <button type="button" class="btn btn-default" id="reset" style="margin-left: 20px;">重置</button>
</form>

<table class="table table-hover">
    <thead>
    <tr>
        <th>注射时间</th>
        <th>餐别</th>
        <th>胰岛素名称</th>
        <th>胰岛素品类</th>
        <th>注射剂量(U)</th>
        <th>注射方式</th>
    </tr>
    </thead>
    <tbody>
    @foreach ($result as $item)
        <tr>
            <td>{{$item->maked_at}}</td>
            <td>
                @switch($item->meals)
                    @case(1)
                        早餐前
                        @break
                    @case(2)
                        中餐前
                        @break
                    @case(3)
                        晚餐前
                        @break
                    @case(4)
                        睡前
                        @break
                    @default
                     @break
                @endswitch
            </td>
            <td>{{$item->insulin_name_cn}}</td>
            <td>{{$item->insulin_type}}</td>
            <td>{{$item->insulin_dosage}}</td>
            <td>
                @switch($item->type)
                    @case(1)
                        医疗建议
                        @break
                    @case(2)
                        用户录入
                        @break
                    @default
                        @break
                @endswitch</td>
        </tr>
    @endforeach
    </tbody>
</table>
{{ $result->appends(['id' => Request::input("id")])->appends(['state' => Request::input("state")])->appends(['meals' => Request::input("meals")])->appends(['maked_at' => Request::input("maked_at")])->links() }}


</body>

<script>
    $('#reset').click(function () {
        $('#meals').val(0);
        $('#state').val(0);
        $('#time_end').val('');
        $('#time_start').val('');
    });
    //查询按钮
    $('#select').click(function () {
        var meals = $('#meals').val();
        var state = $('#state').val();
        var time_end = $('#time_end').val();
        var time_start = $('#time_start').val();
        var id = <?php echo $_GET['id']?>;
        $url = '/admin/user/insulin?id='+ id;
        if ( state >= 0 ) {
            $url += '&state='+state;
        }
        if ( meals ) {
            $url += '&meals='+meals;
        }
        if ( time_end && time_start ) {
            $url += '&maked_at='+time_start+'|'+time_end;
        }else if ( time_end && !time_start ){
            $url += '&maked_at='+time_end+'|'+time_end;
        }else if ( !time_end && time_start  ) {
            $url += '&maked_at='+time_start+'|'+time_start;
        }
        window.location.href = $url;
    });


    //初始化时间插件
    $("#time_start").datetimepicker({
        minView : 2, //  选择时间时，最小可以选择到那层；默认是‘hour’也可用0表示
        language : 'zh-CN', // 语言
        autoclose : true, //  true:选择时间后窗口自动关闭
        format : 'yyyy-mm-dd', // 文本框时间格式，设置为0,最后时间格式为2017-03-23 17:00:00
        todayBtn : true, // 如果此值为true 或 "linked"，则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。
    });
    $("#time_end").datetimepicker({
        minView : 2, //  选择时间时，最小可以选择到那层；默认是‘hour’也可用0表示
        language : 'zh-CN', // 语言
        autoclose : true, //  true:选择时间后窗口自动关闭
        format : 'yyyy-mm-dd', // 文本框时间格式，设置为0,最后时间格式为2017-03-23 17:00:00
        todayBtn : true, // 如果此值为true 或 "linked"，则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。
    })
</script>
